package com.meituan.controller;

import com.meituan.pojo.req.StoresReq;
import com.meituan.pojo.resp.BaseResp;
import com.meituan.service.StoresService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stores")
@Api(description = "店铺相关接口")
public class StoresController {
    @Autowired
    StoresService storesService;
    @ApiOperation("执行时间:点击添加(不传id)或修改(传id)店铺信息后;传入参数:storeReq(店铺对象,包含要添加的店铺所有信息);" +
            "传出参数:BaseResp(1,\"success\",null);可添加属性:sname(店铺名称);surl(店铺图片);address(店铺地址);ftext(店铺备注)")
//    @RequiresPermissions(value ={"stores_update"})
    @PostMapping("insertOrUpdate")
    public BaseResp insert(StoresReq storesReq){
        storesService.insert(storesReq);
        return new BaseResp().SUCCESS();
    }

//    @RequiresPermissions(value ={"stores_delete"})
    @PostMapping("deleteById")
    @ApiOperation("执行时间:点击删除店铺信息后;传入参数:int(整数) sid(店铺id);传出参数:BaseResp(1,\"success\",null);")
    public BaseResp deleteById(int sid){
        storesService.deleteById(sid);
        return new BaseResp().SUCCESS();
    }

    @ApiOperation("执行时间:页面加载后默认执行,查询全部店铺信息;传入参数:不需要传参;传出参数:所有店铺集合List<Stores>;")
//    @RequiresPermissions(value ={"stores_findAll"})
    @PostMapping("findAll")
    public BaseResp findAll(){
        return storesService.findAll();
    }

//    @RequiresPermissions(value ={"stores_findAll"})
    @PostMapping("findByZid")
    @ApiOperation("执行时间:页面加载后默认执行,根据主页分类部分zid查询店铺;传入参数:int(整数)zid(首页头部点击对应的zid值,目前有效值:2);传出参数:所要查询的店铺集合List<Stores>;")
    public BaseResp findByZid(Integer zid){
        return storesService.findByZid(zid);
    }

//    @RequiresPermissions(value ={"stores_findAll"})
    @PostMapping("findByFid")
    @ApiOperation("执行时间:页面加载后默认执行,根据副页分类部分fid查询店铺;传入参数:int(整数)fid(副页头部点击对应的fid值,目前有效值:21,22);传出参数:所要查询的店铺集合List<Stores>;")
    public  BaseResp findByFid(Integer fid){
        return storesService.findByFid(fid);
    }
}
